package com.jun.admin.core.model.enums;

import cn.hutool.core.util.DesensitizedUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.function.Function;

/**
 * @author yuejun.li
 * @date 2024/7/1 14:34:26
 * 脱敏策略枚举
 */
@Getter
@AllArgsConstructor
public enum DesensitizationEnum {
    //手机号脱敏策略，保留前三位和后四位
    PHONE(s -> DesensitizedUtil.desensitized(s, DesensitizedUtil.DesensitizedType.MOBILE_PHONE)),

    //邮箱脱敏策略，保留邮箱用户名第一个字符和@字符前后部分
    EMAIL(s -> DesensitizedUtil.desensitized(s, DesensitizedUtil.DesensitizedType.EMAIL)),

    //身份证号脱敏策略，保留前四位和后四位
    ID_CARD(s -> DesensitizedUtil.desensitized(s, DesensitizedUtil.DesensitizedType.ID_CARD)),

    //地址脱敏策略，保留省市信息，其余部分脱敏
    ADDRESS(s -> DesensitizedUtil.desensitized(s, DesensitizedUtil.DesensitizedType.ADDRESS)),

    //姓名脱敏策略，保留姓氏第一个字符，其余部分脱敏
    NAME(s -> DesensitizedUtil.desensitized(s, DesensitizedUtil.DesensitizedType.CHINESE_NAME));

    private final Function<String,String> desensitization;
}
